import Vue from 'vue'
/**
 * 指令：v-saclick
 * 使用示例：v-saclick="{clickName:'XXX',clickData:{params1:'XXX',params2:'XX'}}"
 * clickName：埋点函数名
 * clickData | Object   params当前埋点函数所需参数
 */
const saclick = Vue.directive('saclick', {
  bind: (el, binding, vnode) => {
    el.addEventListener('click', () => {
      const clickName = binding.value.clickName || '' // 携带的数据
      const data = binding.value.clickData || {} // 接收传参
      vnode.context.$sensors.track(clickName, data)
    })
  }
})

const directives = {
  saclick
}

export default {
  install(Vue) {
    Object.keys(directives).forEach(key => {
      Vue.directive(key, directives[key])
    })
  }
}
